package org.example.road.learn01.handler;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import lombok.extern.slf4j.Slf4j;
import org.example.road.learn01.OutMemoryError2;

@Slf4j
public class ExceptionHandler extends ChannelInboundHandlerAdapter {
    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
        String errorMessage = cause.getMessage();
        if (errorMessage.indexOf("你的主机中") >= 0) {
            final Integer clientId = ctx.channel().attr(OutMemoryError2.idAttr).get();
            log.info("连接{}发生异常", clientId);
        }
        super.exceptionCaught(ctx, cause);
    }
}
